import time
from public.action import *
from public.business import *
from public.testData import *
from public.tools import *

testCase="DBshop005_取消订单"
#打开网页
firefox=openBrowser(url)

#登录会员
DBshopLogin(firefox,userName,password)
#搜索“小米”手机
firefox.find_element_by_xpath('//input[@name="keywords"]').send_keys('小米')
#点击小米手机的图片
firefox.find_element_by_xpath('//input[@type="submit"]').click()
firefox.find_element_by_xpath('//a[@href="/dbshop/goods/8/2"]').click()
switchWindow(firefox,2)
firefox.find_element_by_id('add_cart_submit').click()
time.sleep(2)
firefox.find_element_by_link_text('去购物车结算').click()
firefox.find_element_by_link_text('去结算').click()
firefox.find_element_by_xpath('//input[@value="下一步"]').click()
firefox.find_element_by_xpath('//input[@value="yezf"]').click()
firefox.find_element_by_xpath('//input[@value="确认订单"]').click()

#使用变量orderNO存储订单编号
orderNO=firefox.find_element_by_xpath('(//font[@color="color:#ED145B"])[2]').text
rootPath=get_pro_rootpath()
writeFile(rootPath+'\public\order1.txt',orderNO) # 将订单编号写入到文件中

firefox.find_element_by_xpath('//input[@value="查看订单详情"]').click()
firefox.find_element_by_xpath('//button[text()="取消订单"]').click()
#处理js弹窗，点击“确定”
firefox.switch_to.alert.accept()

#断言
try:
    firefox.find_element_by_link_text(orderNO)
    writeLog("%s 测试通过"%testCase)
except:
    writeLog("%s 测试失败" % testCase)
    getPhoto(firefox)
firefox.quit()

